class Solution {
    public boolean isHappy(int n) {
        List<Integer> list = new ArrayList<>();
        list.add(n);
        while (n != 1) {
            int num = n;
            n = 0;
            while(num != 0) {
                int s = num % 10;
                n += s*s;
                num = num / 10;
            }
            if(list.contains(n)) {
                return false;
            }
            list.add(n);
        }
        return true;
    }
}